/*email validation*/
function checkEmail(emailStr) { 
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
var atom=validChars + "+";
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray == null) {
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat) == null) {
return false;
}
var IPArray = domain.match(ipDomainPat);
if (IPArray != null) {
for (var i = 1; i <= 4; i++) {
if (IPArray[i] > 255) {
return false;
}
}
return true;
}
var domainArray=domain.match(domainPat);
if (domainArray == null) {
return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if ((domArr[domArr.length-1].length < 2) ||(domArr[domArr.length-1].length > 5)) {
return false;
}
if (len < 2) {
return false;
}
}
/* end */
function userReg()
	{
		var t=$('#img').text();
		$('#tag').val(t);
		var letters = /^[a-zA-Z ]*$/; 
		var numbers = /^[0-9]+$/;
		var intgpassword=$('#pass').val();
		var regemailcheck=$('#email').val();
		var cpwd=$('#cpass').val();
		var firstname=$('#fname').val();
		var lastname=$('#lname').val();
		var flag=true;
		if(firstname==""){
			$('#errorfname').html('Required');	
			flag=false;
		}else if(!firstname.match(letters)){
			$('#errorfname').html('');
			$("#errorfname").html("Characters only");
				flag=false;
			}else{
			$('#errorfname').html('');
		}
		
		
		if(lastname==""){
			$('#errorlname').html('Required');
			flag=false;
		}else if(!lastname.match(letters)){
			$('#errorlname').html('');
			$("#errorlname").html("Characters only");
				flag=false;
			}else{
			$('#errorlname').html('');
		}
		
		if(regemailcheck==""){
			$('#erroremail').html('Required');
			$('#regemailchecked').html('');
			flag=false;
		}else if(checkEmail(regemailcheck)==false){	
				$('#erroremail').html('');		
               $('#regemailchecked').html('Enter valid Email id');
               flag=false;
       }else{
			$('#erroremail').html('');
			$('#regemailchecked').html('');
		}
		
		if($('#pnum1').val()==""){
			$('#errorpnum1').html('Required');
			flag=false;
		}else{
			$('#errorpnum1').html('');
		}
	
		if(intgpassword==""){
			$('#errorpass').html('Required');
			$("#errorpassword_numbers").html("");
			$("#lettershide").html("");
			flag=false;
		} else if(intgpassword.length <= 3){
			$('#errorpass').html('4-12 numbers');
			$("#errorpassword_numbers").html("");
			$("#lettershide").html("");
			flag=false;
		} else if(!intgpassword.match(numbers)){
			$('#errorpass').html('');
			$("#lettershide").html("");
			$("#errorpassword_numbers").html("Numbers only");
				flag=false;
		}
		/*
		else{
			$('#errorpassword_numbers').html('');
			$('#errorpass').html('');
			$("#lettershide").html("4-12 numbers, no letters");
		}
		*/
		
		if(cpwd==""){
			$('#errorcpass').html('Required');
			$('#confirmpin').html('');
			flag=false;
		}else if(intgpassword!=cpwd){
			$('#errorcpass').html('PIN mismatch');
			flag=false;
		} else if(cpwd.length <= 3){
			$('#errorpass').html('4-12 numbers');
			$("#errorpassword_numbers").html("");
			$("#lettershide").html("");
			flag=false;
		} 
		
		if(flag==false){
			return false;
		}else{
			return true;
		}
	}	
	function corpReg(){
		var t=$('#img').text();
		$('#tag1').val(t);
		var checkemail=$('#emailadd').val();
		var mobilenumber=$('#mobile').val();
		var IP=$('#IP').val();
		var letters = /^[a-zA-Z ]*$/; 
		var numbers = /^[0-9]+$/;
		var ip = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
		var flag=true;
		if($('#cname').val()==""){
			$('#errorcname').html('Required');
			
			flag=false;
		}else{
			$('#errorcname').html('');
		}
		
		if($('#uname').val()==""){
			$('#erroruname').html('Required');
			flag=false;
		}else{
			$('#erroruname').html('');
		}
		
		if(IP==''){
			$('#errorIP').html('Required');
			flag=false;
		}else{
			var ipsub = new Array();
			ipsub = IP.split(".");
			for (var i = 0; i <ipsub.length; i++) {
				if(ipsub.length==4){
					var sub = parseInt(ipsub[i]);
					if ((isNaN(sub)) || (sub <0) || (sub >255)) {
						$('#errorIP').html('Invalid IP address');
						return false;
					}else{
						$('#errorIP').html('');
					}
				}else{
					$('#errorIP').html('Invalid IP address');
					flag=false;
				}
			}
		}
		
		if($('#password').val()==""){
			$('#errorpassword').html('Required');
			flag=false;
		}else{
			$('#errorpassword').html('');
		}
		
		if($('#cadd').val()==""){
			$('#errorcadd').html('Required');
			flag=false;
		}else{
			$('#errorcadd').html('');
		}
	
		if(checkemail==""){
			$('#erroremailadd').html('Required');
			flag=false;
		
		}else if(checkEmail(checkemail)==false){
				$('#erroremailadd').html('');		
               $('#erroremailaddcheck').html('Enter valid Email id');
               flag=false;
       }else{
			$('#erroremailadd').html('');
			$('#erroremailaddcheck').html('');
		}
		
		if(mobilenumber==""){
			$('#errormobile').html('Required');
			flag=false;
		}else if(!mobilenumber.match(numbers)){
			$('#errormobile').html('');
			$("#errormobile").html("Numbers only");
				flag=false;
			}else{
			$('#errormobile').html('');
		}
		
		if(flag==false){
			return false;
		}else{
			return true;
		}
	}
/*login Page Validations */
function userLogin()
{
		var t=$('#img').text();
		$('#tag').val(t);
		var numbers = /^[0-9]+$/;
		var pnumber=$('#pnumber1').val();
		var Pinnumber=$('#pass').val();
		var flag=true;
		if(pnumber==""){
			$('#errorphonenumber').html('Required');		
			flag=false;
		}else if(!pnumber.match(numbers)){
			$('#errorphonenumber').html('');
			$("#errorphonenumber").html("Numbers only");
				flag=false;
			}else{
			$('#errorphonenumber').html('');
		}
		if($('#pass').val()==""){
			$('#errorpass').html('Required');
			flag=false;
		}else if(!Pinnumber.match(numbers)){
			$('#errorpass').html('');
			$("#errorpass").html("Numbers only");
				flag=false;
			}
		else{
			$('#errorpass').html('');
		}
		if(flag==false){
			return false;
		}else{
			return true;
		}
}
/* Deals page menu active */
function activeMenu(obj)
{
	$("a").removeClass("active");
	$(obj).addClass("active");

}
/* Datepicker */
  
$(function() {
	
	  $('#datepicker').datepicker({showOn: 'both', buttonImage: BASE_PATH+'/images/cal_icon.png', buttonImageOnly: true});
	//$( "#datepicker_to" ).datepicker();
	 $('#datepicker_to').datepicker({showOn: 'both', buttonImage: BASE_PATH+'/images/cal_icon.png', buttonImageOnly: true});
	
	});

/* Account Section validations */
function accountSec(){
	var letters = /^[a-zA-Z ]*$/; 
	var numbers = /^[0-9]+$/;
	var username=$('#uname').val();
	var useremail=$('#Email').val();
	var userpass=$('#pass').val();
	var userconformpass=$('#Cpass').val();
	var flag=true;
	if(username==""){
		$('#uerror').html('Required');		
		flag=false;
	}else if(!username.match(letters)){
		$('#uerror').html('');
		$("#uerror").html("Characters only");
			flag=false;
	}else{
		$('#uerror').html('');
	}
	if(useremail==""){
		$('#uemailerror').html('Required');
		flag=false;
	}else if(checkEmail(useremail)==false){		
         $('#uemailerror').html('Enter valid Email id');
         flag=false;
    }else{
		$('#uemailerror').html('');
	}
	if(userpass==""){
		$('#passworderror').html('Required');
		flag=false;
	}else{
		$('#passworderror').html('');
	}
	if(userconformpass==""){
		$('#conformpassworderror').html('Required');
		flag=false;
	}else if(userpass!=userconformpass){
		$('#conformpassworderror').html('PIN mismatch');
		flag=false;
	}else{
		$('#conformpassworderror').html('');
	}
	if(flag==false){
		return false;
	}else{
		return true;
	}
}
/* User Login CorporateLogin validations */
function corporateLogin(){
	var flag=true;
	if($('#uname').val()== ""){
		$('#erroruname').html('Required');
		flag=false;
	}else{
		$('#erroruname').html('');
	}
	if($('#cpass').val()== ""){
		$('#errorpass_cop').html('Required');
		flag=false;
	}else{
		$('#errorpass_cop').html('');
	}
	if(flag==false){
		return false;
	}else{
		return true;
	}
}
/* USER Setting page validations*/
function settingValidate(){
	var numbers = /^[0-9]+$/;
	var snumber=$('#snum').val();
	var call_number=$('#destnum').val();
	var tags=$('#tags').val();
	var tags1=$('#tags1').val();
	var flag=true;

	if ($("#call_f").is(":checked")) {
		if($('#tags').val()=="" && snumber==''){
			$('#error_snum').html('Required');
			$('#error_conuntry_id').html('Required');
			$('#success').hide();			
			flag=false;
		}else if($('#tags').val()=="" && snumber!='') {
			$('#error_snum').html('');
			$('#error_conuntry_id').html('Required');
			$('#success').hide();
			flag=false;
		}else if($('#tags').val()!="" && snumber=='') {
			$('#error_snum').html('Required');
			$('#error_conuntry_id').html('');
			$('#success').hide();
			flag=false;
		}else if(!snumber.match(numbers)) {
			$('#error_snum').html('');
			$("#error_snum").html("Numbers only");
			$('#success').hide();
			flag=false;
		}
		else if($('#tags').val()!="" && snumber!='') {
			$('#error_conuntry_id').html('');
			$("#error_snum").html('');
			$('#success').hide();
		}
	}
	
	if ($("#call_f1").is(":checked")) {
		if($('#tags1').val()=="" && call_number==''){
			$('#error_destnum').html('Required');	
			$('#error_call_id').html('Required');
			$('#success').hide();
			
			flag=false;
		}else if($('#tags1').val()=="" && call_number!='') {
			$('#error_destnum').html('');	
			$('#error_call_id').html('Required');
			$('#success').hide();
			flag=false;
		} else if($('#tags').val()!="" && call_number=='') {
			$('#error_destnum').html('Required');
			$('#error_call_id').html('');
			$('#success').hide();
			flag=false;
		}else if($('#tags1').val()!="" && call_number!='') {
			$('#error_destnum').html('');
			$("#error_call_id").html('');
			$('#success').hide();
		}else if(!call_number.match(numbers)) {
			$('#error_destnum').html('');
			$("#error_destnum").html("Numbers only");
			$('#success').hide();
			flag=false;
		}
	}
	
	if(flag==false){
		return false;
	}else{
		if (!$("#call_f").is(":checked")) {
			$('#snum').val('');
			$('#tags').val('');
			$('#success').hide();
		}
		if (!$("#call_f1").is(":checked")) {
			$('#destnum').val('');
			$('#tags1').val('');
			$('#success').hide();
		}
		return true;
	}
 }
 function removeRequired(){
 }
function destNumber(){
	if (!jQuery("#call_f").is(":checked")) {
		$("#call_active").html('');
		$("#call_active").text('Call forwarding InActive');
	}else{
		$("#call_active").html('');
		$("#call_active").text('Call forwarding Active');
	}
}
 function disNum(){
	if (!jQuery("#call_f1").is(":checked")) {
	    $("#called_id11").html('');
		$("#called_id11").text('Display called ID InActive');
	}else{
		$("#called_id11").html('');
		$("#called_id11").text('Display called ID Active');
	}
}
/*    END                        */
/* corporate settings start*/
function editValue(){
	var ipnum=$('#ipnum').val();
	var spnum=$('#spnum').val();
}

/* End*/
/* Testimonivals */
  $(function() {
      $('#slides2').slidesjs({
        width: 340,
        height: 95,
        navigation: false,
        start: 1,
        play: {
         auto: true,
		 /*play:500,
		 fadeSpeed:550,
		 slideSpeed:700,
		 pause:10000,
		 effect:'fade',
		 hoverPause:true*/
        }
      });
    });
/* End */
/* Autocomplate */
function countryValue(event, ui){
	var selectedObj = ui.item;
	var value=selectedObj.value;	
	var res = value.split("+");
		res = res[1].substring(0, res[1].length - 1);
		alert(res);
    $('#tags').val('');
	return false;
}

function setCountry(code){
        if(code || code==''){
            var text = jQuery('a[cunt_code="'+code+'"]').html();
            $(".dropdown dt a span").html(text);
        }
    }
    $(document).ready(function() {
        $(".dropdown img.flag").addClass("flagvisibility");

        $(".dropdown dt a").click(function() {

            $(".dropdown dd ul").toggle();
        });

        $(".dropdown dd ul li a").click(function() {
            //console.log($(this).html())
            var text = $(this).html();
            $(".dropdown dt a span").html(text);
            $(".dropdown dd ul").hide();
            $("#result").html("Selected value is: " + getSelectedValue("country-select"));
        });

        function getSelectedValue(id) {
            //console.log(id,$("#" + id).find("dt a span.value").html())
            return $("#" + id).find("dt a span.value").html();
			
        }

        $(document).bind('click', function(e) {
            var $clicked = $(e.target);
            if (! $clicked.parents().hasClass("dropdown"))
                $(".dropdown dd ul").hide();
        });


        $("#flagSwitcher").click(function() {
            $(".dropdown img.flag").toggleClass("flagvisibility");
        });
    });
$(function() {
			var availableTags = [
						"Afghanistan (+93)","Albania ( +355)","Netherlands Antilles (+599)",
						"Algeria (+213)","American Samoa (+1684)","Andorra (+376)","Angola (+244)",
						"Anguilla (+1264)","Antarctica (+672)","Antigua And Barbuda (+1268)",
						"Argentina (+54)","Armenia (+374)","Aruba (+297)","Australia (+61)",
						"Austria (+43)","Azerbaijan (+994)","Bahamas (+1242)","Bahrain (+973)",
						"Bangladesh (+880)","Barbados (+1246)","Belarus (+375)","Belgium (+32)",
						"Belize (+501)","Benin (+229)","Bermuda (+1441)","Bhutan (+975)","Bolivia (+591)",
						"Bosnia and Herzegovina (+387)","Botswana (+267)","Brazil (+55)",
						"Brunei Darussalam (+673)","Bulgaria (+359)","Burkina Faso (+226)",
						"Burundi (+257)","Cambodia (+855)","Cameroon (+237)","Canada (+1)","Cape Verde (+238)",
						"Cayman Islands (+1345)","Central African Republic (+236)","Chad (+235)",
						"Chile (+56)","China (+86)","Colombia (+57)","Comoros (+269)","Congo (+242)",
						"Congo, the Democratic Republic of the (+243)","Cook Islands (+682)",
						"Costa Rica (+506)","Côte dIvoire (+225)","Croatia (+385)","Cuba (+53)",
						"Cyprus (+357)","Czech Republic (+420)","Denmark (+45)","Djibouti (+253)",
						"Dominica (+1767)","Dominican Republic (+1809)","Ecuador (+593)","Egypt (+20)",
						"El Salvador (+503)","Equatorial Guinea (+240)","Eritrea (+291)","Estonia (+372)",
						"Ethiopia (+251)","Falkland Islands (Malvinas) (+500)","Faroe Islands (+298)",
						"Fiji (+679)","Finland (+358)","France (+33)","French Guiana (+594)","French Polynesia (+689)",
						"Gabon (+241)","Gambia (+220)","Georgia (+995)","Germany (+49)","Ghana (+233)",
						"Gibraltar (+350)","Greece (+30)","Greenland (+299)","Grenada (+1473)","Guadeloupe (+590)",
						"Guam (+1671)","Guatemala (+502)","Guinea (+224)","Guinea-Bissau (+245)",
						"Guyana (+592)","Haiti (+509)","Holy See (Vatican City State) (+39)","Honduras (+504)",
						"Hong Kong (+852)","Hungary (+36)","Iceland (+354)","India (+91)","Indonesia (+62)","iNum (+883)",
						"Iran, Islamic Republic of (+98)","Iraq (+964)","Ireland (+353)","Israel (+972)","Italy (+39)",
						"Jamaica (+1876)","Japan (+81)","Jordan (+962)","Kazakhstan (+7)","Kenya (+254)","Kiribati (+686)",
						"Korea Democratic Peoples Republic of (+850)","Korea Republic of (+82)","Kuwait (+965)",
						"Kyrgyzstan (+996)","Lao Peoples Democratic Republic (+856)","Lebanon (+961)",
						"Lesotho (+266)","Liberia (+231)","Libyan Arab Jamahiriya (+218)","Liechtenstein (+423)",
						"Lithuania (+370)","Luxembourg (+352)","Macao (+853)","Macedonia The Former Yugoslav Republic Of (+389)",
						"Madagascar (+261)","Malawi (+265)","Malaysia (+60)","Maldives (+960)","Mali (+223)","Malta (+356)",
						"Marshall Islands (+692)","Martinique (+596)","Mauritania (+222)","Mauritius (+230)",
						"Mayotte (+262)","Mexico (+52)","Micronesia Federated States of (+691)","Moldova Republic of (+373)",
						"Monaco (+377)","Mongolia (+976)","Montenegro (+382)","Montserrat (+1664)",
						"Morocco (+212)","Mozambique (+258)","Myanmar (+95)","Namibia (+264)","Nauru (+674)",
						"Nepal (+977)","Netherlands (+31)","New Caledonia (+687)","New Zealand (+64)",
						"Nicaragua (+505)","Niger (+227)","Nigeria (+234)","Niue (+683)","Northern Mariana Islands (+1670)",
						"Norway (+47)","Oman (+968)","Pakistan (+92)","Palau (+680)","Palestinian Territory, Occupied (+970)",
						"Panama (+507)","Papua New Guinea (+675)","Paraguay (+595)","Peru (+51)",
						"Philippines (+63)","Poland (+48)","Portugal (+351)","Puerto Rico (+1)",
						"Qatar (+974)","Réunion (+262)","Romania (+40)","Russian Federation (+7)",
						"Rwanda (+250)","Saint Helena (+290)","Saint Lucia (+1758)","Saint Pierre and Miquelon (+508)",
						"Saint Vincent and the Grenadines (+1784)","Samoa (+685)","San Marino (+378)",
						"Sao Tome and Principe (+239)","Saudi Arabia (+966)","Senegal (+221)",
						"Serbia (+381)","Seychelles (+248)","Sierra Leone (+232)","Singapore (+65)",
						"Slovakia (+421)","Slovenia (+386)","Solomon Islands (+677)","Somalia (+252)",
						"South Africa (+27)","South Sudan (+211)","Spain (+34)","Sri Lanka (+94)",
						"Sudan (+249)","Suriname (+597)","Swaziland (+268)","Sweden (+46)","Switzerland (+41)",
						"Syrian Arab Republic (+963)","Taiwan (+886)","Tajikistan (+992)","Tanzania United Republic of (+255)",
						"Thailand (+66)","Timor-Leste (+670)","Togo (+228)","Tokelau (+690)","Tonga (+676)",
						"Trinidad and Tobago (+1868)","Tunisia (+216)","Turkey (+90)","Turkmenistan (+993)",
						"Turks and Caicos Islands (+1649)","Tuvalu (+688)","Uganda (+256)","Ukraine (+380)",
						"United Arab Emirates (+971)","United Kingdom (+44)","United States (+1)",
						"Uruguay (+598)","Uzbekistan (+998)","Vanuatu (+678)","Venezuela (+58)",
						"Vietnam (+84)","Virgin Islands British (+1284)","Virgin Islands U.S. (+1340)",
						"Wallis and Futuna (+681)","Yemen (+967)","Zambia (+260)",
						"Zimbabwe (+263)"
				];
			$( "#tags" ).autocomplete({
			source: availableTags,
			select: function (event, ui) {
				var selectedObj = ui.item;
				var value=selectedObj.value;	
				var res = value.split("+");
				res = res[1].substring(0, res[1].length - 1);
				$('#tags').val(res);
				return false;
				}
			});
			$( "#tags1" ).autocomplete({
			source: availableTags,
			select: function (event, ui) {
				var selectedObj = ui.item;
				var value=selectedObj.value;	
				var res = value.split("+");
				res = res[1].substring(0, res[1].length - 1);
				$('#tags1').val(res);
				return false;
				}
			});
		});


